package com.maxd.modules.coupon.mapper;

import com.maxd.model.PublisherOrderDtoBean;
import com.maxd.model.UserInfo;
import com.maxd.modules.coupon.entity.CouponCard;
import org.hibernate.annotations.SQLUpdate;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Auther: Laban:yubo_010@163.com
 * @Date: 2020/11/12 15:10
 * @Description:
 */
@Repository
public interface CouponCardMapper extends JpaRepository<CouponCard, Long> {

    //Page<CouponCard> findAll(Specification<CouponCard> cardFromSpecification,Pageable pageable);

    @Transactional
    @Modifying
    @Query(value = "update sqx_coupon_card set card_user_id=:userId,card_is_activation='1',exchange_time=:exchangeTime  where card_id=:cardId",nativeQuery = true)
    void updateCouponCardByCardId(@Param("exchangeTime") java.util.Date exchangeTime, @Param("cardId") String cardId, @Param("userId") String userId);


    @Query(value = "select * from sqx_coupon_card where card_id=:cardId",nativeQuery = true)
    CouponCard getCouponCardByCardId(@Param("cardId") String cardId);

    @Query(value = "select * from sqx_coupon_card where card_user_id=:userId",nativeQuery = true)
    List<CouponCard> findAllByUserId(String userId);
}
